package com.bowen.demo.oom;

import java.util.HashMap;
import java.util.Map;

/**
 * <h3>java-study</h3>
 * <p>堆内存泄漏</p>
 * @author : zhang.bw
 * @date : 2021-03-25 10:51
 **/
public class MemoryLeakOomError{

	static class Key {
		Integer id;

		Key(Integer id) {
			this.id = id;
		}

		@Override
		public int hashCode() {
			return id.hashCode();
		}

		@Override
		public boolean equals(Object o) {
			boolean response = false;
			if (o instanceof Key) {
				response = (((Key) o).id).equals(this.id);
			}
			return response;
		}
	}

	public static void main(String[] args) {
		Map m = new HashMap<>();
		while (true){
			for (int i=0;i<10000;i++){
				if(m.containsKey(new Key(i))){
					m.put(new Key(i),"Num:"+i);
				}
			}
		}
	}
}

